package com.tocean.app.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public abstract class BaseEntity implements Serializable {

    @ApiModelProperty("标识")
    @NotEmpty(message = "标识不能为空")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @TableField(value = "id")
    private String id;

    @ApiModelProperty("创建人")
    @NotEmpty(message = "创建人不能为空")
    @TableField(value = "created_by", fill = FieldFill.INSERT)
    private String createdBy;

    @ApiModelProperty("创建人名称")
    @NotEmpty(message = "创建人名称不能为空")
    @TableField(value = "created_by_name", fill = FieldFill.INSERT)
    private String createdByName;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull
    @TableField(value = "create_date", fill = FieldFill.INSERT)
    private LocalDateTime createDate;

    @ApiModelProperty("更新人")
    @NotEmpty(message = "更新人不能为空")
    @TableField(value = "last_modified_by", fill = FieldFill.INSERT_UPDATE)
    private String lastModifiedBy;

    @ApiModelProperty("更新人名称")
    @NotEmpty(message = "更新人名称不能为空")
    @TableField(value = "last_modified_by_name", fill = FieldFill.INSERT_UPDATE)
    private String lastModifiedByName;

    @ApiModelProperty("更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @NotNull
    @TableField(value = "last_modified_date", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime lastModifiedDate;

    @ApiModelProperty("是否删除")
    @NotNull
    @TableLogic
    @TableField(value = "is_del", fill = FieldFill.INSERT)
    private Boolean isDel;

}
